package com.gzsxy.JUC.lock;

//synchronized
public class Demo01 {
    public static void main(String[] args) {
        phone phone = new phone();

        new Thread(() -> {
            phone.sms();
        }, "A").start();


        new Thread(() -> {
            phone.call();
        }, "B").start();
    }
}


class phone {

    public synchronized void sms() {
        System.out.println(Thread.currentThread().getName() + "打电话");
        call();//这里也有锁
    }

    public synchronized void call() {
        System.out.println(Thread.currentThread().getName() + "发短信");
    }
}